package com.scs.application.modules.upms.security.utils;

import com.scs.application.consts.ServiceNames;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Description: 仅用于获取oauth相关的配置信息
 */
@Slf4j
public class OauthUtils {

    @Autowired
    private Environment env;

    public String getOauthTokenPrefix() {
        String appname = ServiceNames.OAUTH;
        if (env.getProperty("spring.profiles.active", "dev").indexOf("dev") != -1) {
            // 如果是开发环境下，缓存key通过本机的主机名，避免相互影响
            try {
                appname = InetAddress.getLocalHost().getHostName();
            } catch (UnknownHostException e) {
                log.error("获取主机名出错", e);
            }
        }
        return appname + ":oauth:";

    }
}
